<?php
/**
 * Created by PhpStorm.
 * User: JUAN
 * Date: 2017/10/25
 * Time: 上午10:03
 */
include('./phpqrcode.php');

/**
 * 生成二维码
 * @param $deviceCode
 */
function qrcode($deviceCode) {
    $data = 'http://wechat.houchaowei.com/proxy?deviceCode=' . $deviceCode;
    $filename = "qrcodeImage/" . $deviceCode . '.png';  //  生成的文件名
    $errorCorrectionLevel = 'L';  // 纠错级别：L、M、Q、H
    $matrixPointSize = 7; // 点的大小：1到10
    QRcode::png($data, $filename, $errorCorrectionLevel, $matrixPointSize, 2);
}


/**
 * 合成图片加上水印
 * @param $num
 */
function image($num){
    $filename = 'back2.jpg';
    header('Content-Type: image/jpeg');
    //获取背景图 宽，高
    list($width, $height) = getimagesize($filename);

    $newwidth = 1300;
    $newheight = 400;
    //新建一张画布
    $thumb = imagecreatetruecolor($newwidth, $newheight);
    //引用背景图片
    $source = imagecreatefromjpeg($filename);
    //把背景图片缩放成画布大小插入画布（设置背景图片）
    imagecopyresized($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);

    //引用一张图片当插入图
    $logo = imagecreatefrompng("qrcodeImage/" . $num . ".png");

    //合并图片
    ImageCopy($thumb, $logo, 190, 55, 0, 0, 255, 255);

    //增加文字
    //颜色单位转换
    $hex = str_replace("#", "", "#0000ff");
    if (strlen($hex) == 3) {
        $r = hexdec(substr($hex, 0, 1) . substr($hex, 0, 1));
        $g = hexdec(substr($hex, 1, 1) . substr($hex, 1, 1));
        $b = hexdec(substr($hex, 2, 1) . substr($hex, 2, 1));
    } else {
        $r = hexdec(substr($hex, 0, 2));
        $g = hexdec(substr($hex, 2, 2));
        $b = hexdec(substr($hex, 4, 2));
    }
    //字体
    $ttf = ("t1.ttf");
    //颜色设置
    $color = imagecolorallocate($thumb, 155, 155, 155);
    //插入文字
    imagettftext($thumb, 20, 0, 220, 350, $color, $ttf, $num);
    //输出并保存文件
    imagepng($thumb, "image/" . $num . '.png');
}
